package com.handydata.antifraud.web;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.handydata.antifraud.bo.alarminfo.AlarmInfoReqBO;
import com.handydata.antifraud.bo.alarminfo.AlarmInfoResBO;
import com.handydata.antifraud.common.exception.AlarmInfoExCode;
import com.handydata.antifraud.service.AlarmInfoService;
import com.handydata.antifraud.vo.alarminfo.AlarmInfoBeanVO;
import com.handydata.antifraud.vo.alarminfo.CreateAlarmInfoReqVO;
import com.handydata.antifraud.vo.alarminfo.CreateAlarmInfoResVO;
import com.handydata.antifraud.vo.alarminfo.DeleteAlarmInfoReqVO;
import com.handydata.antifraud.vo.alarminfo.DeleteAlarmInfoResVO;
import com.handydata.antifraud.vo.alarminfo.ModifyAlarmInfoReqVO;
import com.handydata.antifraud.vo.alarminfo.ModifyAlarmInfoResVO;
import com.handydata.antifraud.vo.alarminfo.QueryAlarmInfoReqVO;
import com.handydata.antifraud.vo.alarminfo.QueryAlarmInfoResVO;
import com.handydata.common.convert.CommonBeanConvertor;
import com.handydata.common.web.AbsController;

@RequestMapping("/earlyWarningData")
@RestController
public class AlarmInfoController extends AbsController {
	
	private static final Logger logger = LoggerFactory.getLogger(AlarmInfoController.class);
	
	@Autowired
	private AlarmInfoService alarmInfoService;
	
	@ApiOperation(value="新增告警信息表", notes="新增告警信息表")
	@ApiImplicitParam(name = "req", value = "新增告警信息表请求对象", required = true, dataType = "CreateAlarmInfoReqVO", paramType = "body")
	//@PostMapping("/create")
	@RequestMapping(value = "/create", method = {RequestMethod.POST, RequestMethod.HEAD}, produces = "config/json; charset=UTF-8")

	public CreateAlarmInfoResVO createAlarmInfo(@RequestBody CreateAlarmInfoReqVO req) {

		try {
			logger.info("Execute createAlarmInfo, param is {}", req);
			AlarmInfoReqBO reqBO = CommonBeanConvertor.convert(req, AlarmInfoReqBO.class);
			AlarmInfoResBO resBO = alarmInfoService.createAlarmInfo(reqBO);
			CreateAlarmInfoResVO res = CommonBeanConvertor.convert(resBO, CreateAlarmInfoResVO.class);
			return res;
		} catch (Exception e) {
			return handleException(e, CreateAlarmInfoResVO.class, req, AlarmInfoExCode.SYS_UNKNOWN_ERROR);
		}
	}

	@ApiOperation(value="修改告警信息表", notes="修改告警信息表")
	@ApiImplicitParam(name = "req", value = "修改告警信息表请求对象", required = true, dataType = "ModifyAlarmInfoReqVO", paramType = "body")
	//@PostMapping("/modify")
	@RequestMapping(value = "/modify", method = {RequestMethod.POST, RequestMethod.HEAD}, produces = "config/json; charset=UTF-8")

	public ModifyAlarmInfoResVO modifyAlarmInfo(@RequestBody ModifyAlarmInfoReqVO req) {
		try {
			logger.info("Execute modifyAlarmInfo, param is {}", req);
			AlarmInfoReqBO reqBO = CommonBeanConvertor.convert(req, AlarmInfoReqBO.class);
			AlarmInfoResBO resBO = alarmInfoService.modifyAlarmInfo(reqBO);
			ModifyAlarmInfoResVO res = CommonBeanConvertor.convert(resBO, ModifyAlarmInfoResVO.class);
			return res;
		} catch (Exception e) {
			return handleException(e, ModifyAlarmInfoResVO.class, req, AlarmInfoExCode.SYS_UNKNOWN_ERROR);
		}
	}

	@ApiOperation(value="删除告警信息表", notes="删除告警信息表")
	@ApiImplicitParam(name = "req", value = "修改告警信息表请求对象", required = true, dataType = "DeleteAlarmInfoReqVO", paramType = "body")
	//@PostMapping("/remove")

	@RequestMapping(value = "/remove", method = {RequestMethod.POST, RequestMethod.HEAD}, produces = "config/json; charset=UTF-8")
	public DeleteAlarmInfoResVO deleteAlarmInfo(@RequestBody DeleteAlarmInfoReqVO req) {
		try {
			logger.info("Execute deleteAlarmInfo, param is {}", req);
			AlarmInfoReqBO reqBO = CommonBeanConvertor.convert(req, AlarmInfoReqBO.class);
			AlarmInfoResBO resBO = alarmInfoService.deleteAlarmInfo(reqBO);
			DeleteAlarmInfoResVO res = CommonBeanConvertor.convert(resBO, DeleteAlarmInfoResVO.class);
			return res;
		} catch (Exception e) {
			return handleException(e, DeleteAlarmInfoResVO.class, req, AlarmInfoExCode.SYS_UNKNOWN_ERROR);
		}
	}
	
	@ApiOperation(value="查询告警信息表", notes="根据产品编号、开始时间、结束时间查询预警记录列表数据")
	@ApiImplicitParam(name = "req", value = "查询告警信息表请求对象", required = true, dataType = "QueryAlarmInfoReqVO", paramType = "body")
	//@PostMapping("/earlyWarnRecordListQuery")
	@RequestMapping(value = "/earlyWarnRecordListQuery", method = {RequestMethod.POST, RequestMethod.HEAD}, produces = "config/json; charset=UTF-8")

	public QueryAlarmInfoResVO queryAlarmInfo(@RequestBody QueryAlarmInfoReqVO req) {
		try {
			logger.info("Execute queryAlarmInfo, param is {}", req);
			AlarmInfoReqBO reqBO = CommonBeanConvertor.convert(req, AlarmInfoReqBO.class);
			AlarmInfoResBO resBO = alarmInfoService.queryAlarmInfo(reqBO);
			QueryAlarmInfoResVO res = CommonBeanConvertor.convert(resBO, QueryAlarmInfoResVO.class, AlarmInfoBeanVO.class);

			return res;
		} catch (Exception e) {
			return handleException(e, QueryAlarmInfoResVO.class, req, AlarmInfoExCode.SYS_UNKNOWN_ERROR);
		}
	}

	
}
